'use strict';

const BaseController = require('../base');
const { Op } = require('sequelize');
class TicketShopController extends BaseController {
  static get serviceName() {
    return 'business.ticketShop';
  }

  afterFormatQuery(where, query) {
     if (query.keyword) {
       // 使用或的关系处理以上like
       where[ Op.or ] = [
         { name: { [Op.like]: `%${query.keyword}%` } },
         { description: { [Op.like]: `%${query.keyword}%` } },
         { content: { [Op.like]: `%${query.keyword}%` } }
       ]
     } else {
       delete where.keyword
     }
     return where
  }

  async login() {
    const { ctx, service } = this;
    const { username, password } = ctx.request.body;
    const result = await service.business.ticketShop.login(username, password);
    this.ctx.success(result)
  }
}

module.exports = TicketShopController;
